﻿/*
Desc:MediatR事件基类
Author:Joker
CreatedDate:24-02-02
*/

using ElectronicMall.Domain.Abstractions.Events;
using ElectronicMall.Utilities.TypeExtensions;
using MediatR;

namespace ElectronicMall.Domain.Buses.MediatR.Events
{
    /// <summary>
    /// MediatR事件基类
    /// </summary>
    public abstract class MediatREvent : IEvent, INotification
    {
        public string Id { get; }

        public DateTimeOffset Timestamp { get; }

        public MediatREvent(string? eventId = null)
        {
            if (eventId is not null && eventId.IsNullOrWhiteSpace())
            {
                throw new ArgumentException($"{eventId}的值不能是空白的。", nameof(eventId));
            }

            Id = eventId ?? Guid.NewGuid().ToString();
            Timestamp = DateTimeOffset.Now;

        }
    }
}
